package ThreadDemo;

import java.util.Scanner;

public class ThreadDemo7 {
    public static void main(String[] args) {
        Object locker=new Object();
        Thread thread1=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker) {
                    System.out.println("请输入一个数");
                    Scanner scanner = new Scanner(System.in);
                    int a = scanner.nextInt();
                }
            }
        });
        thread1.start();
        Thread thread2=new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    synchronized (locker) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("这是线程2");
                    }
                }
            }
        });

        thread2.start();
    }
}
